using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using Atom.Data.BusinessObjects;
using Atom.Data.Base;

namespace Atom.Data.ManagerObjects
{
    public partial interface IHBalanceRecordManager : IManagerBase<Atom.Data.BusinessObjects.HBalanceRecord, string>
    {
		// Get Methods
		HBalanceRecord GetById(System.Int32 balanceid, System.Int32 operatetype, System.String invoiceid);
    }

    partial class HBalanceRecordManager : ManagerBase<Atom.Data.BusinessObjects.HBalanceRecord, string>, IHBalanceRecordManager
    {
		#region Constructors
		
		public HBalanceRecordManager() : base()
        {
        }
        public HBalanceRecordManager(INHibernateSession session) : base(session)
        {
        }
		
		#endregion
		
        #region Get Methods

		public override HBalanceRecord GetById(string id)
		{
			string[] keys = id.Split('^');
			
			if(keys.Length != 3)
				throw new Exception("Invalid Id for HBalanceRecordManager.GetById");
			
			return GetById(System.Int32.Parse(keys[0]), System.Int32.Parse(keys[1]), keys[2]);
		}
		public HBalanceRecord GetById(System.Int32 balanceid, System.Int32 operatetype, System.String invoiceid)
		{
			ICriteria criteria = Session.GetISession().CreateCriteria(typeof(HBalanceRecord));
			
			criteria.Add(NHibernate.Criterion.Expression.Eq("Balanceid", balanceid));
			criteria.Add(NHibernate.Criterion.Expression.Eq("Operatetype", operatetype));
			criteria.Add(NHibernate.Criterion.Expression.Eq("Invoiceid", invoiceid));
			
			HBalanceRecord result = (HBalanceRecord)criteria.UniqueResult();

            if (result == null)
                throw new NHibernate.ObjectDeletedException("", null, null);

            return result;
		}
		
		
		#endregion
    }
}